package morenoapp.model.impl.index;

import morenoapp.model.data.MorenoAnswerFace;
import morenoapp.model.data.MorenoAnswerItemFace;
import morenoapp.model.data.MorenoMeasureFace;
import morenoapp.model.data.MorenoModelFace;
import morenoapp.model.data.MorenoQuestionFace;
import morenoapp.model.data.MorenoRespondentFace;
import morenoapp.model.index.MorenoRespondentIndex;

/**
 *
 * @author dmitry.mamonov
 */
public class MorenoRespondentReceivedPreferencesWeightIndexImpl 
        extends MorenoQuestionDerivedIndexImpl
        implements MorenoRespondentIndex{
    private MorenoMeasureFace measure;
    public MorenoRespondentReceivedPreferencesWeightIndexImpl(MorenoModelFace _model, String _type, MorenoQuestionFace _question,MorenoMeasureFace _measure) {
        super(_model, _type, _question);
        assert _measure!=null;
        this.measure = _measure;
    }


    @Override
    public double getIndexValue(MorenoRespondentFace _resp) {
        double weight = 0.0;
        for(MorenoRespondentFace resp:getModel().getRespondentsList()){
            MorenoAnswerFace answer = resp.getAnswerByQuestion(getQuestion());
            MorenoAnswerItemFace item = answer.getAnswerItemByRespondent(_resp);
            if (item!=null){
                weight+=measure.getWeight(item.getQuestionItem().getItemNumber());
            }
        }
        return weight;
    }

}
